import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';
import { Component, OnInit} from '@angular/core';
// import { ToastService, UploadConfig } from 'ng-tui';
import { GlobalService, AuthService } from '../../../../cores/services';
import { ManageService } from '../../services/manage.service';
import { Manage } from '../../interfaces/manage.interface';
import { ActivatedRoute, Router } from '@angular/router';
import { Pagination, ConfirmService, ToastService, Item } from 'ng-tui';
import { ApiData, SearchParams } from '../../../../cores/classes';
import { Goods } from '../../interfaces/manage.interface';
import { skipWhile, switchMap } from 'rxjs/operators';

@Component({
    templateUrl: './attendance-leave.component.html',
    providers: [Location, { provide: LocationStrategy, useClass: PathLocationStrategy }],
})
export class AttendanceLeaveComponent implements OnInit {
    theads = ['#', '申请时间', '申请人', '部门', '职务', '账号', '起始日期', '结束日期', '请假天数', '请假时长', '请假原因',
        '审核人', '审核时间', '状态',  '操作'];

    search = new SearchParams({ start: '', end: '' });

    list = new Array<Goods>();

    loading = false;

    pagination = new Pagination();
    parentTypes = new Array<Item>();
    childTypes = new Array<any>();
    goodsThreeType = new Array<any>();
    goods: Goods = { id: 0, isActive: 1, goodsName: '' };


    get getChildTypes(): Item[] {
        return this.childTypes.filter(type => type.parentId === this.goods.goodsParentType);
    }
    get getThreeTypes(): Item[] {
        return this.childTypes.filter(type => type.parentId === this.goods.goodsParentType);
    }
    constructor(
        private activatedRoute: ActivatedRoute,
        private router: Router,
        private confirm: ConfirmService,
        private toast: ToastService,
        public global: GlobalService,
        private manageService: ManageService
    ) { }

    ngOnInit() {
        this.activatedRoute.url
            .pipe(skipWhile(() => this.router.url !== '/manage/account'))
            .subscribe(() => this.loadDatas());
    }
    // doSearch() {
    //     this.pagination.reset();
    //     this.loadDatas();
    // }

    // doReset() {
    //     this.search.clean();
    //     this.doSearch();
    // }

    loadDatas() {
        this.loading = true;
        this.manageService.searchGoods(this.pagination, this.search)
            .subscribe({
                next: res => {
                    this.pagination.total = res.datas.total;
                    this.list = res.datas.rows;
                },
                complete: () => this.loading = false
            });
    }

    // confirmDelete(goods: Goods) {
    //     this.confirm.danger('删除确认', `您确认删除商品'${goods.goodsName}'吗？`)
    //         .pipe(switchMap<void, ApiData>(() => this.manageService.deleteGoods(goods.id)))
    //         .subscribe(() => {
    //             this.list.splice(this.list.indexOf(goods), 1);
    //             this.toast.success('删除成功', `成功删除商品'${goods.goodsName}`);
    //             this.loadDatas();
    //         });
    // }

}
